package com.dingceng.demo

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.dingceng.demo.base.dp
import com.dingceng.demo.base.router.PATH_PHOTO_LIST_ACTICITY
import com.dingceng.demo.base.router.PATH_DOUBAN_CARD_ACTICITY
import com.dingceng.demo.base.ui.BaseActivity
import com.dingceng.demo.base.ui.MyGridItemDecoration
import com.dingceng.demo.databinding.ActivityMainBinding

class MainActivity : BaseActivity<ActivityMainBinding>(), View.OnClickListener {
    private val adapter = MainAdapter()

    override fun provideLayout(): Int {
        return R.layout.activity_main
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.click = this
        initRecyclerView()
    }

    private fun initRecyclerView() {
        val layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        binding.recyclerView.addItemDecoration(MyGridItemDecoration(15.dp, false, 10.dp))
        binding.recyclerView.layoutManager = layoutManager
        binding.recyclerView.adapter = adapter
        adapter.setList(listOf("打开图片列表","仿豆瓣FM卡片滑动","尽情期待..."))
        adapter.setOnItemClickListener { _, view, position ->
            when(position){
                0->{
                    startActivity(Intent(this, Class.forName(PATH_PHOTO_LIST_ACTICITY)))
                }
                1->{
                    startActivity(Intent(this, Class.forName(PATH_DOUBAN_CARD_ACTICITY)))
                }
            }
        }
    }

    override fun onClick(v: View?) {
        when(v?.id){
        }
    }
}